<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of validator
 *
 * @author chaporgin_a
 */
abstract class VA_Form_Validator {
  private $initOptions = array();

  protected $errorMessages = array();
  /**
   * To put the Validator into active state one should call this first
   * @param array $options
   */
  public function init(array $options) {
    $this->initOptions = $options;
  }
  /**
   * Устанавливает опцию по-умолчанию, если опция еще не установлена
   * @param string $name
   * @param mixed $value
   */
  public function setInitOptionIfNone($name, $value){
    $this->initOptions[$name] = $value;
    return $this;
  }
  /**
   * To serialize the validator you get all the needed options calling this function
   *
   * After that you can call init with options received from getInitOptions and it MUST work
   * To make it consistent
   * developer MUST take care of these 2 functions: init and getInitOptions
   *
   * @return array
   */
  public function getInitOptions() {
    return $this->initOptions;
  }
  /**
   * Check if value is valid
   *
   * @param string $value
   */
  abstract public function isValid($value);
  /**
   * @return array
   */
  public function getErrorMessages() {
    return $this->errorMessages;
  }
  /**
   *
   * @return array
   */
  abstract public function getHTMLTagAttributes();

  protected function getOption($name, $default = null){
    if(!key_exists($name, $this->initOptions) && (null === $default))
            throw new Exception(sprintf('required option "%s" is missing!', $name));
    if(key_exists($name, $this->initOptions)) return $this->initOptions[$name];
    else return $default;
  }
}
?>
